Accessibility

Transitioning from a Display to an Input Form

To transition the application from a display to an input form and back, you will:

  1. Add an Add New Part option at the top of the ListBox.
  2. Hide the TextBox that displays the part type.
  3. Display the ComboBox and the PushButton when the user clicks the Add New Part option.
  4. Populate the ComboBox with all part types retrieved from the database.

Add a new option to a ListBox that uses bindFormatFunction(). Typically, to add an option to a ListBox you simply use the following code:

parts_lb.addItemAt(0,"Add New Part",null);

This inserts the Add New Part text as the first (remember the ListBox is zero-indexed) option in the box. There is no data associated with this option. However, in this tutorial, you use the bindFormatFunction(), complicating the insertion a bit more.

Remember, the binder function assigned the name property of a record to the label part of what displayed. You will add Add New Part to the ListBox when using bindFormatFunction() using the following steps:

  1. Create a temporary object of the Object class.
  2. Assign a name property with the value Add New Part to the object.
  3. Add the object to the RecordSet.
  4. Use bindFormatFunction() as you did before.

Using bindFormatStrings(). The DataGlue object also has the bindFormatStrings() method, in addition to the bindFormatFunction() that you have already used. Using bindFormatStrings() is easier, because you don’t have to write any extra functions to use it. The general format is:

DataGlue.bindFormatStrings(dataConsumer,
		   RecordSet,
		   "#labelColumnName#",
		   "#dataColumnName#");

Note: When filling the label and data portions, you only use the string value from a single column of the RecordSet returned. Earlier in the tutorial you used the bindFormatFunction() instead of the bindFormatStrings(), because at that point, you needed to store an entire record in the data portion.

Exercise 4

In this exercise you will learn how to add a new option to the top of the ListBox, retrieve part types from the database, display the results, and transition to the view interface.

  1. Adding a New Option to the Top of the ListBox

    1. In devnet.fla, locate the partResponder.onResult method in the object methods section.
    2. As the first line of the code in the method, create a variable local to the function named tempObj. tempObj is an object of the Object class.
    3. In the method, set a name property of the new object equal to the text Add New Part.
    4. In the method, use the addItemAt() method to add the new object to the parts_rs RecordSet at the 0th position.
    5. To automatically highlight the first part instead of the newly added text, change the setSelectedIndex() argument to 1 instead of 0 in the method.
    6. Ensure your function now appears as shown here:

      partResponder.onResult=function(parts_rs){
      			var tempObj=new Object;
      			tempObj.name="Add New Part";
      			parts_rs.addItemAt(0,tempObj);
      			DataGlue.bindFormatFunction(parts_lb,parts_rs,binder);
      			parts_lb.setSelectedIndex(1);
      		}
    7. Save the document and test the movie. You should now see that the first option in the ListBox is the text Add New Part. Also note that the app the first actual part name is selected and its details are displayed.
  2. Retrieving All Possible Part Types from the Database. When supplying part data in the input form, users should only be able to choose certain part types from a ComboBox. The part types in the ComboBox are retrieved from the database.
    1. Open the CFC in Dreamweaver MX. In this exercise, you will retrieve the part types for the ComboBox from the database. The CFC uses a <cfquery> tag and a SQL SELECT statement. The tag is shown here:

      <cfquery name="qGetTypes" datasource="bikeparts">
      			SELECT	partTypeID, partType
      			FROM	PartType 
      			ORDER BY partType ASC
      		</cfquery>
    2. In the object creation section, create an object named typeResponder using the following syntax:

      var typeResponder=new Object();
    3. In the run at once commands section, just below where you invoked the getPartInfo() method, invoke the getPartTypes() method, as follows:

      partService.getPartTypes(typeResponder);
    4. At the top of the object methods section, create the skeleton for the onResult method attached to the object you just created. Use as the argument the variable types_rs.
    5. In the method, assign a variable named partTypes_rs the variable that was used as the argument, types_rs.

      Note: You need to reassign the variable because types_rs is by default local to the function and would not have meaning outside of the function. You will need to use the RecordSet returned in another location on the page, so you are simply creating a variable you can use in other locations.

    6. Check to make sure your method appears as follows:

      typeResponder.onResult=function(types_rs){
      			partTypes_rs=types_rs;
      		}
  3. Writing the Method to Transition the Display into an Input Form

    1. At the top of the object methods section, create a skeleton for an addPart method attached to the parts_lb object, as shown here:

      parts_lb.addPart=function(){
      		}
    2. In the function, use the _visible property of the type_txt object to hide it.
    3. In the method, use the _visible property to make both the types_cb and addPart_pb objects visible.
    4. In the method, clear any data in the following TextBoxes by setting the text property equal to the empty string:

      • name_txt
      • type_txt
      • price_txt
      • desc_txt
    5. In the method, use the bindFormatStrings() method to populate the ComboBox types_cb. Users should be able to see the partType and assign the partTypeID to the data. Use the following values:

      • dataConsumer: types_cb
      • dataProvider: partTypes_rs
      • labelString: "#partType#"
      • dataString: "#partTypeID#"
    6. Ensure your method appears as shown here:

      parts_lb.addPart=function(){
      			type_txt._visible=false;
      			types_cb._visible=true;
      			addPart_pb._visible=true;
      			name_txt.text="";
      			type_txt.text="";
      			price_txt.text="";
      			desc_txt.text="";
      			DataGlue.bindFormatStrings(types_cb,partTypes_rs, "#partType#","#partTypeID#");
      		}
  4. Transition back to the display

    1. In the object methods section, locate the parts_lb.fillTextBoxes method.
    2. At the top of the method, set the _visible property of the following objects to the value shown:

      • type_txt: true
      • types_cb: false
      • addParts_pb: false
    3. Check to be sure your method appears as shown here:

      parts_lb.fillTextBoxes=function(){
      			type_txt._visible=true;
      			types_cb._visible=false;
      			addPart_pb._visible=false;
      			name_txt.text=parts_lb.getSelectedItem().data.name;
      			type_txt.text=parts_lb.getSelectedItem().data.partType;
      			price_txt.text=parts_lb.getSelectedItem().data.price;
      			desc_txt.text=parts_lb.getSelectedItem().data.description;
      		}
  5. Invoke the correct method. You now have two different methods that you must call based on what the user selects in the ListBox. When the user clicks the text Add New Part, invoke the addPart method, and when the user clicks any actual part, invoke the fillTextBoxes method. Write a simple method to invoke the correct method using the following steps:

    1. At the top of the object methods section, create a skeleton for a displayOrAdd method attached to the parts_lb object, as follows:

      parts_lb.displayOrAdd=function(){
      		}
    2. In the method, use an if statement that checks the following criteria:

      • If the text Add New Part was clicked in the ListBox.
      • If the condition is true, it invokes the parts_lb.AddPart() method.
      • If the condition is false, it invokes the parts_lb.fillTextBoxes() method.
    3. Ensure your method appears as shown here:

      parts_lb.displayOrAdd=function(){
      			if (parts_lb.getSelectedIndex() == 0){
      			parts_lb.addPart();
      			}else{
      			parts_lb.fillTextBoxes();
      			}
      		}
    4. In the event handler assignment section, change the setChangeHandler for parts_lb to invoke displayOrAdd instead of fillTextBoxes, as follows:

      parts_lb.setChangeHandler("displayOrAdd",parts_lb);
    5. Save the document and test the movie. When you click a part in the ListBox, the details display as they did before this exercise. If you click Add New Part, the dynamically populated ComboBox appears along with the PushButton. If you click a part again, the part details should appear.

< Back | Contents | Next >

Submit feedback on our tutorials, articles, and sample applications.